package com.cml.application;


import com.cml.common.constant.NodeStatus;
import com.cml.common.context.ServerContext;
import com.cml.domain.service.ServerNodeRebalanceService;
import com.cml.domain.service.ServiceInstanceReplicasManagerService;

/**
 * 姓名：陈茂林
 * 时间：2023/10/7 9:02
 * 描述：
 */
public class ServerNodeApplication {

    public ServerNodeApplication(){
    }

    public void start( ServerContext serverContext){
        serverContext.getServerNodeManagerService().start();
        ServerNodeRebalanceService serverNodeRebalanceService=
                new ServerNodeRebalanceService.Builder(serverContext).build();
        //判断是否处于 可伸缩的节点状态
        if(NodeStatus.getInstance().getCurStatus().equals(NodeStatus.NODE_HA)){
            //进入HA模式，所有的槽分配情况需要进行重构
            serverNodeRebalanceService.rebalance(serverContext.getServerNode());
        }else{
            serverContext.getSoltManagerService().startSoltManagerProcess();
        }
        serverContext.getServiceManagerService().start();
        serverNodeRebalanceService.startRebalanceListen();

    }
}
